﻿using System;
using Const;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public static GameManager ins;

    private UIController _ui;
    private PlayController _play;
    private Wall _wall;
    private EState _state;
    private float _score=0.0f;

    public float score
    {
        get => _score;
        set => _score = value;
    }

    public EState state
    {
        get => _state;

        set
        {
            _state = value;
            _ui.ChangeUI(value);
            _play.ChangeState(value);
        }
    }

    public void ResetWall()
    {
        _wall.ResetWall();
    }
    
    public bool isCross(float x)
    {
        return _play.transform.position.x > x + 10f;
    }
    
    void Awake()
    {
        ins = this;
    }

    void Start()
    {
        _play = GameObject.Find("Player").GetComponent<PlayController>();
        _ui = GameObject.Find("Canvas").GetComponent<UIController>();
        _wall= GameObject.Find("Wall").GetComponent<Wall>();
        state = EState.START;
    }

    private void Update()
    {
        if (Input.GetKeyDown((KeyCode.Escape)))
        {
            Application.Quit();
        }
    }
}